(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

// If obj.hasOwnProperty has been overridden, then calling
// obj.hasOwnProperty(prop) will break.
// See: https://github.com/joyent/node/issues/1707
function hasOwnProperty(obj, prop) {
  return Object.prototype.hasOwnProperty.call(obj, prop);
}

module.exports = function(qs, sep, eq, options) {
  sep = sep || '&';
  eq = eq || '=';
  var obj = {};

  if (typeof qs !== 'string' || qs.length === 0) {
    return obj;
  }

  var regexp = /\+/g;
  qs = qs.split(sep);

  var maxKeys = 1000;
  if (options && typeof options.maxKeys === 'number') {
    maxKeys = options.maxKeys;
  }

  var len = qs.length;
  // maxKeys <= 0 means that we should not limit keys count
  if (maxKeys > 0 && len > maxKeys) {
    len = maxKeys;
  }

  for (var i = 0; i < len; ++i) {
    var x = qs[i].replace(regexp, '%20'),
        idx = x.indexOf(eq),
        kstr, vstr, k, v;

    if (idx >= 0) {
      kstr = x.substr(0, idx);
      vstr = x.substr(idx + 1);
    } else {
      kstr = x;
      vstr = '';
    }

    k = decodeURIComponent(kstr);
    v = decodeURIComponent(vstr);

    if (!hasOwnProperty(obj, k)) {
      obj[k] = v;
    } else if (isArray(obj[k])) {
      obj[k].push(v);
    } else {
      obj[k] = [obj[k], v];
    }
  }

  return obj;
};

var isArray = Array.isArray || function (xs) {
  return Object.prototype.toString.call(xs) === '[object Array]';
};

},{}],2:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';

var stringifyPrimitive = function(v) {
  switch (typeof v) {
    case 'string':
      return v;

    case 'boolean':
      return v ? 'true' : 'false';

    case 'number':
      return isFinite(v) ? v : '';

    default:
      return '';
  }
};

module.exports = function(obj, sep, eq, name) {
  sep = sep || '&';
  eq = eq || '=';
  if (obj === null) {
    obj = undefined;
  }

  if (typeof obj === 'object') {
    return map(objectKeys(obj), function(k) {
      var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
      if (isArray(obj[k])) {
        return map(obj[k], function(v) {
          return ks + encodeURIComponent(stringifyPrimitive(v));
        }).join(sep);
      } else {
        return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
      }
    }).join(sep);

  }

  if (!name) return '';
  return encodeURIComponent(stringifyPrimitive(name)) + eq +
         encodeURIComponent(stringifyPrimitive(obj));
};

var isArray = Array.isArray || function (xs) {
  return Object.prototype.toString.call(xs) === '[object Array]';
};

function map (xs, f) {
  if (xs.map) return xs.map(f);
  var res = [];
  for (var i = 0; i < xs.length; i++) {
    res.push(f(xs[i], i));
  }
  return res;
}

var objectKeys = Object.keys || function (obj) {
  var res = [];
  for (var key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  }
  return res;
};

},{}],3:[function(require,module,exports){
'use strict';

exports.decode = exports.parse = require('./decode');
exports.encode = exports.stringify = require('./encode');

},{"./decode":1,"./encode":2}],4:[function(require,module,exports){
var { Point } = require("./Point.js");

// var k1 = 1
class Plot {
  static viewv = {
    left: 0,
    top: 0,
    k1: 1
  };
  /**
   * Creates an instance of Plot.
   * 画布，所有被画出来的元素都append到这个container
   * @memberof Plot
   * @param canvasDom {HTMLCanvasElement}
   */
  constructor(canvasDom) {

    /**
     * @type {HTMLCanvasElement}
     */
    this.container = canvasDom; //
    canvasDom.width = document.body.clientWidth;
    canvasDom.height = document.body.clientHeight;
    //  初始化长宽
    canvasDom.style.width = document.body.clientWidth + "px";
    canvasDom.style.height = document.body.clientHeight + "px";
    this.context = this.container.getContext("2d");
    //原点
    this.radius = 2; // 点的半径
    /**
     * @type {Point}
     */
    this.origin = new Point(0, 0);
    // this.context.setTransform

    this.context.translate(this.container.width / 2, this.container.height / 2);
    this.context.rotate(Math.PI * 1.5);
    //坐标颜色
    this.baseLineColor = "black";
    //画笔颜色
    this.brushColor = "red";
    //画笔粗细

    this.gain = 1;
    // this.drawCoordinate();
    this.initKeyEvent();
    this.points = [];
    this.lines = [];
    this.clean()
    //baseLineX，baseLineY保存坐标线，用于坐标移位
    //初始化方法，设置画布，原点位置，坐标线颜色，画笔颜色，画笔粗细
    //  var rect = canvas.getBoundingClientRect();
  }

  init(baseLineColor, brushColor) {
    this.baseLineColor = baseLineColor;
    this.brushColor = brushColor;
    this.drawCoordinate();
  }
  /**
   * 原点
   * @param {any} p
   * @memberof Plot
   */
  setOPoint(p) {
    if (p.x != undefined && p.y != undefined) this.origin = p;
    this.context.translate(
      this.container.width / 2 + p.x,
      this.container.height / 2 + p.y
    );
    this.drawCoordinate();
  }
  //画坐标线
  drawCoordinate() {
    var height = this.container.height;
    var width = this.container.width;
    this.line(
      { x: 0, y: -height / 2 }, //this.container.width / 2
      { x: 0, y: height / 2 }
    );
    this.line({ x: -width, y: 0 }, { x: width, y: 0 });
  }
  //清理画布，移走所有对象
  clean() {
    // this.context.fillStyle = "#000000";
    // this.context.beginPath(); 
    // this.container.width/2
    // this.context.fillRect(-Infinity, -Infinity, Infinity, Infinity);
    // this.context.closePath();
    // console.log(-this.container.width / 2, -this.container.height / 2, 2 * this.container.width, 2 * this.container.height)
    // this.context.clearRect(-this.container.width / 2, -this.container.height / 2, 2 * this.container.width, 2 * this.container.height);
    // this.drawCoordinate();
    this.fillColor([0, 1, 0, 255])
  }
  
  fillColor(color4) {
    var { context } = this;
    let { width: w, height: h } = this.container
    var a = context.getImageData(0, 0, w, h)
    var data = a.data
    var [cr, cg, cb, ca] = color4
    for (let index = 0, len = data.length; index < len;) {
      data[index++] = cr
      data[index++] = cg
      data[index++] = cb
      data[index++] = ca
    }
    context.putImageData(a, 0, 0);
  }

  drawColor(cb) {
    var { context } = this;
    let { width: w, height: h } = this.container
    var a = context.getImageData(0, 0, w, h)
    context.putImageData(a, 0, 0);
  }
  
  /**
   * // 画点，相对原点  //div 绘制点 
   * @param {*} p 
   * @param {*} color 
   */
  drawDot(p, color) {
    if (!(p.x != undefined && p.y != undefined))
      return; //校验
    this.context.beginPath();
    this.context.arc(p.y, p.x, this.radius, 0, Math.PI * 2, false); //x ,y r ,stangle
    this.context.closePath();
    this.context.fillStyle = color || this.brushColor;
    //本来这里最初使用的是red，
    this.context.fill();
  }
  /**
   * 
   *   //画线从(x0,y0)到(x1,y1)
   * @param {*} point0 
   * @param {*} point1 
   * @param {string} color 
   */
  line(point0, point1, color = "red") {
    //竖线
    this.context.lineWidth = this.radius / 2;
    this.context.save();
    this.context.beginPath();
    this.context.moveTo(point0.y, point0.x); //将画笔移到x0,y0处//point0.x,
    this.context.lineTo(point1.y, point1.x); //从x1,y1到x2,y2画条线
    this.context.strokeStyle = color;
    this.context.stroke(); //画线
    this.context.restore();
  }
  drawPoint(p, color) {
    this.points.push([p, color]);
    this.drawDot(p, color)
  }
  drawNodeSet(nodes, color = "red") {
    //绘制节点集合
    // if (nodes) 
    // this.points = this.points.concat(nodes);
    for (var index in nodes) {
      this.drawDot(nodes[index], color);
    }
  }
  drawLine(point0, point1) {
    this.lines.push([point0, point1]);
    this.line(point0, point1);
  }
  reDraw() {
    this.points.forEach((params) => {
      this.drawDot.apply(this, params)
    });
    this.lines.forEach((params) => {
      this.line.apply(this, params)
    })
  }

  initKeyEvent() {
    let movd = 5;
    
    console.log(" // 38 40 |37 39 // 上下 左右  [] 放大缩小")
    document.addEventListener("keydown", e => {
      var viewv = Plot.viewv
      //this.origin.y -= movd * k1;
      var centerX = viewv.left + this.container.width / 2 * viewv.k1;
      var centerY = viewv.top + this.container.height / 2 * viewv.k1;
      switch (e.which) {
        case 38:
          this.context.translate(-movd * viewv.k1, 0);
          viewv.top -= movd * viewv.k1;
          break;
        case 40:
          this.context.translate(movd *viewv. k1, 0);
          viewv.top += movd * viewv.k1;
          break;
        case 37:
          this.context.translate(0, -movd *viewv. k1);
          viewv.left -= movd * viewv.k1;
          break;
        case 39:
          this.context.translate(0, movd * viewv.k1);
          viewv.left += movd * viewv.k1;
          break;
        case 221:
          this.context.scale(0.8, 0.8);
          this.radius /= 0.8
          viewv. k1 *= 0.8;
          viewv.top = centerY - viewv.k1 * this.container.height / 2;
          viewv.left = centerX - viewv.k1 * this.container.width / 2;
          break;
        case 219:
          this.context.scale(1 / 0.8, 1 / 0.8);
          this.radius *= 0.8
          viewv.k1 *= 1.25;
          viewv.top = centerY - viewv.k1 * this.container.height / 2;
          viewv.left = centerX - viewv.k1 * this.container.width / 2;
          break;
      }

      this.clean();
      this.reDraw();
    });
  }
  /**
   * @param {{x:number,y:number}[]} list
   */
  drawList(list) {
    var viewv = Plot.viewv
    var k1 = viewv.k1
    var a, p
    this.COLOR = 255
    var { context, COLOR } = this;
    context.shadowColor = "#000"
    let { width: w, height: h } = this.container
    let b = (a = context.getImageData(0, 0, w, h)).data; // let
    for (let index = 0, len = b.length; index < len;) {
      b[index++] = 0
      b[index++] = 0
      b[index++] = 0
      b[index++] = 255
    }
    let dlen = b.length;
    for (let i = 0, len = list.length; i < len; i++) {
      p = list[i];
      let x13 = (p.x - viewv.left) / k1;
      let y13 = (p.y - viewv.top) / k1;
      if (x13 < 0 || x13 >= w || y13 < 0 || y13 >= h) continue;
      let n = ~~(x13 + ~~y13 * w) * 4;
      if (n < 0 || n >= dlen - 3) {
        continue;
      }
      // @ts-ignore
      b[n] = b[n + 1] = b[n + 2] = p.COLOR || COLOR, b[n + 3] = 255
    }
    context.putImageData(a, 0, 0);
  }
  
  /**
   * 
   * @param {number[]} color 
   */
  pickColor(color, diff = 1) {
    var data = this.context.getImageData(0, 0, this.container.width, this.container.height).data;
    var list = [];
    var { k1, left, top } = Plot.viewv
    var w = this.container.width;
    for (let index = 0, len = data.length; index < len; index += 4) {
      var w0 = (index / 4) % w;
      var h0 = ((index / 4) - w0) / w;
      // && data[index + 1] == color[1] && data[index + 2] == color[2] && data[index + 3] == color[3]
      // todo
      if (Math.abs(data[index] - color[0]) <= diff
        && Math.abs(data[index + 1] - color[1]) <= diff
        && Math.abs(data[index + 2] - color[2]) <= diff
        && Math.abs(data[index + 3] - color[3]) <= diff
      ) {
        list.push({ x: w0 * k1 + left, y: h0 * k1 + top })
      }
    }
    return list
  }
  get center() {
    var { k1, left, top } = Plot.viewv
    return { x: this.container.width / 2 * k1 + left, y: this.container.height * k1 + left }
  }
}
module.exports = { Plot };

},{"./Point.js":5}],5:[function(require,module,exports){
class Point {
  /** @type {Number} */
  vx;
  /** @type {Number} */
  vy;

  /**
   *  x,y构造
   * @param {Number} x
   * @param {Number} y
   */
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
  /**
   *  欧式距离
   * @param {Point} point1
   * @param {Point} point2
   */
  static len(point1, point2) {

    var len = Math.sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y)
    );
    len = Math.max(len, 1e-7)
    return len;
  }

  /**
   * 
   * @param {{x:number,y:number}[]} ps 
   */
  static countCenter(ps) {
    var sumx = 0, sumy = 0;
    ps.forEach(v => {
      sumx += v.x;
      sumy += v.y;
    })
    return { x: sumx / ps.length, y: sumy / ps.length }
  }
  /**
   * 检查对象格式
   * @param {Point} obj
   */
  static check(obj) {
    return obj && obj.x && obj.y;
  }

  /**
   * 
   * @param {Point[]} points 
   */
  static sumV(points) {
    var sv = 0;
    for (let index = 0, len = points.length; index < len; index++) {
      // const element = points[index];
      sv += (points[index].vx ** 2 + points[index].vy ** 2) ** 0.5
    }
    return sv;
  }
}
module.exports = { Point }

},{}],6:[function(require,module,exports){
/*
会飞的字
*/


var { Plot } = require("../Plot.js");
var { Point } = require("../Point")
/**
 * @type {HTMLCanvasElement}
 */
var canvasDom = document.querySelector("#myCanvas");
var plot = new Plot(canvasDom)
var context = canvasDom.getContext("2d");
canvasDom.width = document.body.clientWidth;;
canvasDom.height = document.body.clientHeight;

var querystring = require("querystring");
var params = querystring.parse(location.search.slice(1));

context.font = `normal ${canvasDom.height * 0.3}px "楷体"`;
params.word = params.word || '人'
context.strokeText(params.word , canvasDom.width / 2 - canvasDom.height * 0.3 / 2 * params.word.length, canvasDom.height / 2 );

setTimeout(function () {
	/**
	 * @type {{x:number,px:number,y:number,py:number,s:number,a:number}[]}
	 */
	// @ts-ignore
	var list = plot.pickColor([0, 0, 0, 255], 50);
	var center = plot.center;
	var lenList2Center = []
	for (let index = 0, len = list.length; index < len; index++) {
		// const element = array[index];
		list[index].px = list[index].x;
		list[index].py = list[index].y;

		// @ts-ignore
		lenList2Center.push(Point.len(list[index], center))
	}
	var maxLeng = Math.max(...lenList2Center);
	var circleR = maxLeng * 1.1;
	// debugger

	for (let index = 0, len = list.length; index < len; index++) {
		var angle = Math.atan((list[index].py - center.y) / (list[index].px - center.x));
		if (list[index].x - center.x < 0) {
			angle += Math.PI;
		}
		// @ts-ignore
		// lenList2Center.push(Point.len(list[index], center))
		list[index].s = Math.asin(lenList2Center[index] / circleR )
		list[index].a = Math.asin(angle / Math.PI / 2 )//- 0.5
	}

	var tick = 0;
	list.forEach(v => {
		v.px = v.x;
		v.py = v.y;
	})
	plot.drawList(list);

	function draw() {
		tick++;
		var center = plot.center;
		for (var i = 0; i < list.length; i++) {
			var ag = (Math.sin(list[i].a + tick * 0.005) + 0.5) * Math.PI * 2;
			var ll = (Math.sin(list[i].s + tick * 0.01) + 0.5) * circleR
			list[i].x = ll * Math.cos(ag) + center.x;
			list[i].y = ll * Math.sin(ag) + center.y;

			// angle /= Math.PI / 360; 
		}
		plot.drawList(list);

	}
	setInterval(draw, 10);
	globalThis.list = list;

}, 1000)



// var list = getPoints()
// var context = plot.context;
// context.font = 'normal 28pt "楷体"';
// context.fillStyle = "#000000";
// context.clearRect(0,0,canvas.width,canvas.height);  


},{"../Plot.js":4,"../Point":5,"querystring":3}]},{},[6]);
